﻿using Lan.ServiceCore.Services;
using Lan.ServiceCore.TargetCollection;
using Model;
using System.Data;

namespace Lan.Database
{
    public class CameraDatabase 
    {
        public static WCamera[] GetCameras()
        {
            CameraService cameraService = new CameraService();
            var ds = cameraService.GetAllList();

            if (ds.Count == 0)
                return new WCamera[0];

            List<WCamera> list = new List<WCamera>(ds.Count);
            foreach (CameraModel dtRow in ds)
            {
                try
                {
                    WCamera camera = new WCamera(dtRow);
                    list.Add(camera);
                }
                catch (System.Exception ex)
                {
                    //Log.Error("从数据库加载相机失败：\r\n" + ex.ToString());
                    Console.WriteLine("从数据库加载相机失败：\r\n" + ex.ToString());
                }
            }

            return list.ToArray();
        }

        //internal static int GetMaxId()
        //{
        //    string cmd = "select max(ID) from camera";
        //    object value = null;// DB.GetSingle(cmd);
        //    int id;
        //    if (value != null && int.TryParse(value.ToString(), out id))
        //        return id;
        //    return -1;
        //}

        //public static Dictionary<string, int> GetAllCompany()
        //{
        //    string cmd = "select ID,Company from rtspaddrformats";
        //    DataSet ds = null;// DB.Query(cmd);
        //    DataRowCollection rows = ds.Tables[0].Rows;
        //    if (rows.Count == 0)
        //        return new Dictionary<string, int>();

        //    Dictionary<string, int> dic = new Dictionary<string, int>(rows.Count);
        //    foreach (DataRow row in rows)
        //    {
        //        try
        //        {
        //            int id = int.Parse(row["ID"].ToString());
        //            string company = row["Company"].ToString();
        //            dic[company] = id;
        //        }
        //        catch { }
        //    }
        //    return dic;
        //}
    }
}
